void setup(){

  pinMode(A0,INPUT);
  pinMode(A1,OUTPUT); 
  pinMode(A2,INPUT);
  pinMode(A3,INPUT);
  pinMode(A4,INPUT);
  pinMode(A5,INPUT);
  digitalWrite(A1,HIGH);
  Serial.begin(115200);
}
void loop(){
  byte tmp = data();
  Serial.print(tmp);
}

byte baca(){
  byte temp = 0;
  if(digitalRead(A0) == LOW){
    temp = (digitalRead(A5) ) | (digitalRead(A4) << 1) | (digitalRead(A3) << 2) | (digitalRead(A2) << 3);
//Serial.println(temp);
  }
  
  return temp;
}
//ACK itu active low
byte data(){
  byte  x=0;  
  while(digitalRead(A0) == HIGH){
  }
  x=baca() << 4;//MSB
  digitalWrite(A1,LOW);//ACK
  while(digitalRead(A0) == LOW){
  }
  digitalWrite(A1,HIGH);//reset ack
  while(digitalRead(A0) == HIGH){
  }
  x += baca();
  digitalWrite(A1,LOW);//ACK
  while(digitalRead(A0) == LOW){
  }
  digitalWrite(A1,HIGH);//reset ACK
  return x;
}


